<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Registration</title>

    <link href="css/style.css" rel="stylesheet">
    <link href="css/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
</head>

<body class="login-body">

<div class="container">

    <form class="form-signin" th:action="@{saveadmin}">
        <div class="form-signin-heading text-center">
            <h1 class="sign-title">新用户注册</h1>
            <img src="images/login-logo.png" alt=""/>
        </div>


        <div class="login-wrap">


            <p>输入您的帐户详细信息如下</p>
            <input type="text" th:onblur="|checkadmin(this)|" name="adminname" autofocus="" placeholder="用户名" class="form-control">
            <input type="password"   name="password" id="password" placeholder="密码" class="form-control">
            <input type="password" th:onblur="|adminword()|" id="password1" name="password1" placeholder="确认密码" class="form-control">
              <span id="No" style="display: none;color:red">密码不一致</span>
            <div id="msg" style="padding-top: 10px; display: none">
                <label  id="tip">用户名不合法</label>
            </div>

            <label class="checkbox">
                <input type="checkbox" value="agree this condition"> 我同意服务条款和隐私政策
            </label>
            <button type="submit" class="btn btn-lg btn-login btn-block">
                <span>注册</span>
            </button>

            <div class="registration">
                已经注册。
                <a th:href="@{login}" class="">
                    去登陆
                </a>
            </div>

        </div>

    </form>

</div>
<script th:inline="javascript">
    //获取应用路径
    var contextPath = [[${#request.getContextPath()}]];



</script>
<script type="text/javascript">

    function checkadmin(obj) {
        $.ajax({
            url: contextPath + "/checkadmin",
            data:{"adminname":obj.value},
            method:"post",
            success:function (data) {
                $("#msg").css("display","block");
                if (data == 102) {//用户存在
                    $("#tip").html("用户名不合法");
                    $("#tip").removeClass("alert-success");
                    $("#tip").addClass("alert-danger");
                } else {
                    $("#tip").html("用户名可以注册");
                    $("#tip").removeClass("alert-danger");
                    $("#tip").addClass("alert-success");
                }
            }
        })
    }
    function adminword() {

        var password1 =  document.getElementById("password1").value;
        var password =  document.getElementById("password").value;
        if (password==password1){
            $("#No").css("display","none");

        }else {
            $("#No").css("display","block");

        }

    }
</script>



<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/modernizr.min.js"></script>

</body>
</html>
